/*
$(document).ready(function () {

    $('#tblUser').datagrid({
        url:'user/list',
        columns:[
            [
                {field:'username', title:'Tên đăng nhập', width:100},
                {field:'name', title:'Tên người dùng', width:100},
                {field:'phone_number', title:'Số điện thoại', width:100, align:'right'},
                {field:'email', title:'Email', width:100, align:'right'}
            ]
        ],
        toolbar:'#toolbar',
        rownumbers:'true',
        fitColumns:'true',
        singleSelect:'true'
    });

});

var url;
function newUser() {
    $('#dlg').dialog('open').dialog('setTitle', 'New User');
    $('#fm').form('clear');
    url = 'save_user.php';
}
function editUser() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        $('#dlg').dialog('open').dialog('setTitle', 'Edit User');
        $('#fm').form('load', row);
        url = 'update_user.php?id=' + row.id;
    }
}
function saveUser() {
    $('#fm').form('submit', {
        url:url,
        onSubmit:function () {
            return $(this).form('validate');
        },
        success:function (result) {
            var result = eval('(' + result + ')');
            if (result.success) {
                $('#dlg').dialog('close');		// close the dialog
                $('#dg').datagrid('reload');	// reload the user data
            } else {
                $.messager.show({
                    title:'Error',
                    msg:result.msg
                });
            }
        }
    });
}
function removeUser() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        $.messager.confirm('Confirm', 'Are you sure you want to remove this user?', function (r) {
            if (r) {
                $.post('remove_user.php', {id:row.id}, function (result) {
                    if (result.success) {
                        $('#dg').datagrid('reload');	// reload the user data
                    } else {
                        $.messager.show({    // show error message
                            title:'Error',
                            msg:result.msg
                        });
                    }
                }, 'json');
            }
        });
    }
}

*/
